package graph.drawingshapes
{
	import flash.display.GradientType;
	import flash.display.Graphics;
	
	import mx.events.PropertyChangeEvent;
	
	public class GradientFill extends BaseFill
	{
		public static const DefaultGradientType:String = GradientType.LINEAR;
		[Bindable]
		private var _gradientType:String = DefaultGradientType;
		[Bindable]
		public function get gradientType():String
		{
			return this._gradientType;
		}
		public function set gradientType(value:String):void
		{
			if (value.length == 0) throw new ArgumentError("GradientType value couldn't be empty.");
			if (value != this._gradientType)
			{
				var event:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(this, "gradientType", this.gradientType, value);
				dispatchEvent(event);
				this._gradientType = value;
			}
		}
		
		public static const DefaultColors:Array = [0x3CB371,0x3C7EB2];
		[Bindable]
		private var _colors:Array = DefaultColors;
		[Bindable]
		public function get colors():Array
		{
			return this._colors;
		}
		public function set colors(value:Array):void
		{
			if (value.length < 2) throw new ArgumentError("Colors array should contain at least 2 elements.");
			if (value != this._colors)
			{
				var event:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(this, "colors", this.colors, value);
				dispatchEvent(event);
				this._colors = value;
			}
		}
		
		public static const DefaultAlphas:Array = [1,1];
		[Bindable]
		private var _alphas:Array = DefaultAlphas;
		[Bindable]
		public function get alphas():Array
		{
			return this._alphas;
		}
		public function set alphas(value:Array):void
		{
			if (value.length < 2) throw new ArgumentError("Alphas array should contain at least 2 elements.");
			if (value != this._alphas)
			{
				var event:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(this, "alphas", this.alphas, value);
				dispatchEvent(event);
				this._alphas = value;
			}
		}
		
		public static const DefaultRatios:Array = [0,255];
		[Bindable]
		private var _ratios:Array = DefaultRatios;
		[Bindable]
		public function get ratios():Array
		{
			return this._ratios;
		}
		public function set ratios(value:Array):void
		{
			if (value.length < 2) throw new ArgumentError("Ratios array should contain at least 2 elements.");
			if (value != this._ratios)
			{
				var event:PropertyChangeEvent = PropertyChangeEvent.createUpdateEvent(this, "ratios", this.ratios, value);
				dispatchEvent(event);
				this._ratios = value;
			}
		}
		
		public function GradientFill(gradientType:String = DefaultGradientType)
		{
			super();
		}
		
		public override function beginFill(graphics:Graphics):Graphics
		{
			graphics.beginGradientFill(gradientType, colors, alphas, ratios);
			return graphics;
		}
	}
}